package com.hnhs.controller;

import com.hnhs.model.Category;
import com.hnhs.model.CategoryQuery;
import com.hnhs.model.Product;
import com.hnhs.model.ProductQuery;
import com.hnhs.service.CategoryService;
import com.hnhs.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin // 后台解决跨域的问题
@RequestMapping("/api/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     *  code=1
     *  msg="成功"
     *  data=[{}]
     *  统一返回值
     */
   // @GetMapping("/api/category")
    @GetMapping
    public List<Product> select(ProductQuery query){
        List<Product> select = productService.select(query);

//        if(1==1){
//            throw new BizException(88,"报错了 拜拜了您呢");
//        }
        return  select;
    }
    @PostMapping
   public Integer insert(@RequestBody Product product){
        return productService.insert(product);
   }

    @PutMapping
    public Integer update(@RequestBody Product product){
        return  productService.update(product);
    }
    @DeleteMapping
    public Integer delete(Integer id){
        return  productService.updateStatus(id);
    }
}
